#include "GUIDataInletWidget.h"
#include "ui_GUIDataInletWidget.h"

#include "FITK_Interface/FITKInterfaceCustomData/FITKCDDataInlet.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
#include "OperatorsInterface/TreeEventOperator.h"

using namespace GUI;

GUIDataInletWidget::GUIDataInletWidget(Interface::FITKCDDataInlet* obj, EventOper::ParaWidgetInterfaceOperator* oper, QWidget* parent) :
	GUIWidgetBase(parent), _oper(oper), _obj(obj)
{
	_ui = new Ui::GUIDataInletWidget();
	_ui->setupUi(this);

	init();
}

GUIDataInletWidget::~GUIDataInletWidget()
{
	if (_ui) {
		delete _ui;
		_ui = nullptr;
	}
}

void GUIDataInletWidget::init()
{
	_ui->comboBox_Inlet_Shape->addItems(QStringList() << "Round" << "Rectangle");

	setDataToWidget();
}

void GUIDataInletWidget::setDataToWidget()
{
	_ui->lineEdit_Name->setText(_obj->getDataObjectName());
	_ui->comboBox_Inlet_Shape->setCurrentIndex(_obj->getInlet_Shape());
	_ui->doubleSpinBox_Position0->setValue(_obj->getPosition()[0]);
	_ui->doubleSpinBox_Position1->setValue(_obj->getPosition()[1]);
	_ui->doubleSpinBox_Position2->setValue(_obj->getPosition()[2]);
	_ui->doubleSpinBox_Flow_Rate0->setValue(_obj->getFlow_Rate()[0]);
	_ui->doubleSpinBox_Flow_Rate1->setValue(_obj->getFlow_Rate()[1]);
	_ui->doubleSpinBox_Flow_Rate2->setValue(_obj->getFlow_Rate()[2]);
	_ui->doubleSpinBox_Inlet_Area->setValue(_obj->getInlet_Area());
}


void GUIDataInletWidget::on_lineEdit_Name_editingFinished()
{
	_obj->setDataObjectName(_ui->lineEdit_Name->text());

	auto treeOper = Core::FITKOperatorRepo::getInstance()->getOperatorT<EventOper::TreeEventOperator>("ModelTreeEvent");
	if (treeOper != nullptr)
	{
		treeOper->updateTree();
	}
}
void GUIDataInletWidget::on_comboBox_Inlet_Shape_activated(int index)
{
	_obj->setInlet_Shape(index);
}
void GUIDataInletWidget::on_doubleSpinBox_Position0_valueChanged(double value)
{
	auto d = _obj->getPosition();
	d[0] = value;
	_obj->setPosition(d);
}
void GUIDataInletWidget::on_doubleSpinBox_Position1_valueChanged(double value)
{
	auto d = _obj->getPosition();
	d[1] = value;
	_obj->setPosition(d);
}
void GUIDataInletWidget::on_doubleSpinBox_Position2_valueChanged(double value)
{
	auto d = _obj->getPosition();
	d[2] = value;
	_obj->setPosition(d);
}
void GUIDataInletWidget::on_doubleSpinBox_Flow_Rate0_valueChanged(double value)
{
	auto d = _obj->getFlow_Rate();
	d[0] = value;
	_obj->setFlow_Rate(d);
}
void GUIDataInletWidget::on_doubleSpinBox_Flow_Rate1_valueChanged(double value)
{
	auto d = _obj->getFlow_Rate();
	d[1] = value;
	_obj->setFlow_Rate(d);
}
void GUIDataInletWidget::on_doubleSpinBox_Flow_Rate2_valueChanged(double value)
{
	auto d = _obj->getFlow_Rate();
	d[2] = value;
	_obj->setFlow_Rate(d);
}
void GUIDataInletWidget::on_doubleSpinBox_Inlet_Area_valueChanged(double value)
{
	_obj->setInlet_Area(value);
}
